/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.anhanguera.tcc.view;

import com.anhanguera.tcc.model.Usuario;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.NoResultException;
import javax.persistence.PersistenceContext;

/**
 *
 * @author Diego
 */
@Stateless
public class UsuarioFacade extends AbstractFacade<Usuario> {

    @PersistenceContext(unitName = "tcc-warPU")
    private EntityManager em;

    @Override
    protected EntityManager getEntityManager() {
        return em;
    }

    public UsuarioFacade() {
        super(Usuario.class);
    }

    public Usuario autentica(Usuario u) {
        try {
            return this.em.createNamedQuery("Usuario.autentica", Usuario.class).setParameter(1, u.getSenha()).setParameter(2, u.getNuCpf()).getSingleResult();
        } catch (NoResultException nre) {
            System.out.println("Usuario nao encontrado:" + nre.getLocalizedMessage());
            return null;
        }
    }

}
